import { post } from "./request";

export const getTaskType = async () => {
  try {
    const res = await post("/dictionary/taskType");
    return res.data.map((item) => item.columns);
  } catch (error) {
    console.log("error==", error);
    return null;
  }
};

export const getUserById = async (id) => {
  const res = await post("/my/otherPeople", {
    id: id,
  });
  return res.data?.columns;
};

/**
 * 格式化时长显示
 * @param minutes 分钟数
 * @returns 格式化后的时长字符串
 */
export const formatDuration = (minutes) => {
  if (!minutes || Number(minutes) <= 0) {
    return "暂无";
  }

  const totalMinutes = Math.round(Number(minutes));
  const hours = Math.floor(totalMinutes / 60);
  const remainingMinutes = totalMinutes % 60;

  if (hours === 0) {
    return `${remainingMinutes}分钟`;
  } else if (remainingMinutes === 0) {
    return `${hours}小时`;
  } else {
    return `${hours}小时${remainingMinutes}分钟`;
  }
};
